/**
 * @Author: GuoXinyuan
 * @Date: 2021/4/28
 */
export const usernameState = {
    pass: Symbol(),
    errType: Symbol(),
    tooShort: Symbol(),
    tooLong: Symbol(),
    illegalChar: Symbol(),
}

export const passwordState = {
    pass:Symbol(),
    errType: Symbol(),
    tooShort: Symbol(),
    tooLong: Symbol(),
    illegalChar: Symbol()
}

export const verifyUsername =  function(username){
    if((typeof username) !== 'string') return usernameState.errType;
    if(username.length < 4) return usernameState.tooShort;
    if(username.length > 30) return usernameState.tooLong;
    let pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]");
    if(pattern.test(username)) return usernameState.illegalChar;
    return usernameState.pass;
}

export const verifyPassword = function (password) {
    if((typeof password) !== 'string') return passwordState.errType;
    if(password.length < 6) return passwordState.tooShort;
    if(password.length > 30) return passwordState.tooLong;
    let pattern = new RegExp("[a-zA-Z0-9_]");
    if(!pattern.test(password)) return passwordState.illegalChar;
    return passwordState.pass;
}
